package gui.panel_new.evaluation.student;

import enums.ExtensionEnum;
import enums.OposicionValuesEnum;
import enums.TextBundleEnum;
import enums.URLEnum;
import gui.panel_new.evaluation.exeptions.ExerciseNotBuiltException;
import gui.panel_new.evaluation.exeptions.PunctuationZeroException;
import j_util.Utiles;
import misc.BundlesProvider;
import model.Premisa;
import model.eval.TestExcercise;
import model.mchoice.OposicionMCItem;
import model.mchoice.OposicionMCItemSet;

import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Date: Oct 9, 2009
 * Time: 11:58:44 PM
 * @author Jose Martin Rozanec;
 */
public class OposicionEvaluationPanel extends ExercisePanel {
    private JLabel answersLabel;
    private JLabel firstAnswerLabel;
    private JLabel secondAnswerLabel;
    private JLabel thirdAnswerLabel;
    private JLabel fourthAnswerLabel;
    private JTextField firstAnswerTextField;
    private JTextField secondAnswerTextField;
    private JTextField thirdAnswerTextField;
    private JTextField fourthAnswerTextField;
    private JCheckBox true1;
    private JCheckBox true2;
    private JCheckBox true3;
    private JCheckBox true4;
    private JCheckBox false1;
    private JCheckBox false2;
    private JCheckBox false3;
    private JCheckBox false4;
    private JCheckBox indeterminated1;
    private JCheckBox indeterminated2;
    private JCheckBox indeterminated3;
    private JCheckBox indeterminated4;
    private JLabel addsPoints;
    private JLabel substractPoints;
    private JTextField addsPointsField;
    private JTextField substractPointsField;
    private JButton previousQuestionButton;
    private JButton nextQuestionButton;
    private JTextArea fullQuestionaireTextArea;
    private JTextField questionsQuantityTextField;
    private JCheckBox proportionalPunctuationCheckBox;
    private JCheckBox oneAnswerPerQuestionCheckBox;
    private JTextField substractProportionalityTextField;
    private JButton createExerciseButton;
    private JTextField premisaField;
    private JCheckBox verdadera;
    private JCheckBox falsa;
    private JCheckBox indeterminada;

    private ButtonGroup group1;
    private ButtonGroup group2;
    private ButtonGroup group3;
    private ButtonGroup group4;

    private ResourceBundle textBundle;
    private JPanel questionsPanel;

    private OposicionMCItemSet oposicionMCItemSet;
    private OposicionMCItemSet studentsSolutionsMCItemSet;
    private Premisa premisa;
    private int answers;

    public OposicionEvaluationPanel() {
        oposicionMCItemSet = new OposicionMCItemSet();
        initComponents();
        initGUI();
        enableAnswers();
    }

    private void initComponents() {
        textBundle = BundlesProvider.getBundle(URLEnum.TEXT_BUNDLE);
        answersLabel = new JLabel(textBundle.getString(TextBundleEnum.ANSWERS.toString()));
        firstAnswerLabel = new JLabel("A- ");
        secondAnswerLabel = new JLabel("E- ");
        thirdAnswerLabel = new JLabel("I- ");
        fourthAnswerLabel = new JLabel("O- ");
        firstAnswerTextField = new JTextField(25);
        secondAnswerTextField = new JTextField(25);
        thirdAnswerTextField = new JTextField(25);
        fourthAnswerTextField = new JTextField(25);
        true1 = new JCheckBox();
        true2 = new JCheckBox();
        true3 = new JCheckBox();
        true4 = new JCheckBox();
        false1 = new JCheckBox();
        false2 = new JCheckBox();
        false3 = new JCheckBox();
        false4 = new JCheckBox();
        indeterminated1 = new JCheckBox();
        indeterminated2 = new JCheckBox();
        indeterminated3 = new JCheckBox();
        indeterminated4 = new JCheckBox();
        addCheckBoxesActionListeners();

        premisaField = new JTextField(30);
        verdadera = new JCheckBox("V");

        falsa = new JCheckBox("F");
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(verdadera);
        buttonGroup.add(falsa);
        buttonGroup.add(indeterminada);

        addsPoints = new JLabel(textBundle.getString(TextBundleEnum.SUMA.toString()));
        substractPoints = new JLabel(textBundle.getString(TextBundleEnum.RESTA.toString()));
        addsPointsField = new JTextField(5);
        substractPointsField = new JTextField(5);
        substractPointsField.setEditable(false);
        previousQuestionButton = new JButton(textBundle.getString(TextBundleEnum.PREVIOUS.toString()));
        nextQuestionButton = new JButton(textBundle.getString(TextBundleEnum.NEXT.toString()));
        setButtonsSize(nextQuestionButton);
        setButtonsSize(previousQuestionButton);
        fullQuestionaireTextArea = new JTextArea(16, 48);// rows;columns
        questionsQuantityTextField = new JTextField(32);
        questionsQuantityTextField.setText("10");
        proportionalPunctuationCheckBox = new JCheckBox(
                textBundle.getString(TextBundleEnum.FIXED_PUNCTUATION.toString()));
        oneAnswerPerQuestionCheckBox = new JCheckBox(textBundle.getString(
                TextBundleEnum.ONE_ANSWER_PER_QUESTION.toString()));
        substractProportionalityTextField = new JTextField(22);
        substractProportionalityTextField.setText("0.5");
        substractProportionalityTextField.setToolTipText(
                textBundle.getString(
                        TextBundleEnum.SUBSTRACT_PER_QUESTION_PROPORTIONALITY_TOOLTIP.toString()));
        createExerciseButton = new JButton(textBundle.getString(
                TextBundleEnum.CREATE_EXCERCISE.toString()));
        questionsPanel = new JPanel();
        addButtonsActionListeners();

        group1 = new ButtonGroup();
        group2 = new ButtonGroup();
        group3 = new ButtonGroup();
        group4 = new ButtonGroup();

        group1.add(true1);
        group1.add(false1);
        group1.add(indeterminated1);

        group2.add(true2);
        group2.add(false2);
        group2.add(indeterminated2);

        group3.add(true3);
        group3.add(false3);
        group3.add(indeterminated3);

        group4.add(true4);
        group4.add(false4);
        group4.add(indeterminated4);
    }

    private void initGUI() {
        setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        add(createQuestionCreationPanel(), gridBagConstraints);
//        add(createMCItemSetOptionsPanel(), gridBagConstraints);
        gridBagConstraints.gridy = 1;
        enableQuestionsPanel(false);
    }

    private JPanel createMCItemSetOptionsPanel() {
        int x = 0;
        int y = 0;
        JPanel panel = new JPanel();
        panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK),
                textBundle.getString(TextBundleEnum.MULTIPLE_CHOICE_TEST_OPTIONS.toString())));
        panel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        JPanel auxPanel1 = new JPanel();
        auxPanel1.setLayout(new GridBagLayout());
        gridBagConstraints.gridwidth = 6;//5
        auxPanel1.add(new JLabel(textBundle.getString(
                TextBundleEnum.QUESTIONS_QUANTITY.toString()) + ": "), gridBagConstraints);
        x = 6;//5
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridwidth = 9;//10
        auxPanel1.add(questionsQuantityTextField, gridBagConstraints);
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridwidth = 30;
        panel.add(auxPanel1, gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 22;//11
        panel.add(proportionalPunctuationCheckBox, gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 17;//8
        JPanel auxPanel2 = new JPanel(new GridBagLayout());
        auxPanel2.add(new JLabel(textBundle.getString(
                TextBundleEnum.SUBSTRACT_PER_QUESTION_PROPORTIONALITY.toString()) + ": "), gridBagConstraints);
        x = 17;//8
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridwidth = 13;//7
//        substractProportionalityTextField=new JTextField(22); //15
        auxPanel2.add(substractProportionalityTextField, gridBagConstraints);
        gridBagConstraints.gridwidth = 30;
        gridBagConstraints.gridx = 0;
        panel.add(auxPanel2, gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.add(createExerciseButton, gridBagConstraints);
        //cantidad de preguntas, puntuacion proporcional, si existe una respuesta estricta por pregunta
        return panel;
        //ver posibilidad de revisar las preguntas...
    }

    private JPanel createQuestionCreationPanel() {
        int x = 0;
        int y = 0;
        questionsPanel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        fullQuestionaireTextArea.setEditable(false);
        questionsPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.BLACK),
                textBundle.getString(TextBundleEnum.PREGUNTA.toString()) + " 1 " +
                        textBundle.getString(TextBundleEnum.DE.toString()) + " " + oposicionMCItemSet.getTotalQuestions()));
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        gridBagConstraints.gridwidth = 4;
        questionsPanel.add(createQuestionPanel(), gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridwidth = 2;
        questionsPanel.add(answersLabel, gridBagConstraints);
        x = 2;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridwidth = 1;
        questionsPanel.add(createCheckLinePanel(), gridBagConstraints);
        gridBagConstraints.gridwidth = 1;
        gridBagConstraints.gridheight = 3;
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(createScoringPanel(), gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridheight = 1;
        questionsPanel.add(firstAnswerLabel, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(firstAnswerTextField, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(createCheckLinePanel1(), gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        questionsPanel.add(secondAnswerLabel, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(secondAnswerTextField, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(createCheckLinePanel2(), gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        questionsPanel.add(thirdAnswerLabel, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(thirdAnswerTextField, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(createCheckLinePanel3(), gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        questionsPanel.add(fourthAnswerLabel, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(fourthAnswerTextField, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        questionsPanel.add(createCheckLinePanel4(), gridBagConstraints);
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        x = 0;
        gridBagConstraints.gridx = x;
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridwidth = 4;
        questionsPanel.add(createButtonsPanel(), gridBagConstraints);
        gridBagConstraints.gridy = ++y;
        gridBagConstraints.gridheight = 9;//6
        questionsPanel.add(createFullQuestionairePanel(), gridBagConstraints);
        clearAllFields();
        return questionsPanel;
    }

    private JPanel createCheckLinePanel() {
        JPanel panel = new JPanel(new GridBagLayout());
        int x = 0;
        int y = 0;
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 15, 5, 10);
        panel.add(new JLabel("V"), gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(new JLabel("F"), gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(new JLabel("V/F"), gridBagConstraints);
        return panel;
    }

    private JPanel createQuestionPanel() {
        int x = 0;
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 2, 5, 2);
        gridBagConstraints.gridx = x;
        panel.add(new JLabel(textBundle.getString(TextBundleEnum.PREMISA.toString())), gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(premisaField, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SPACE_OP))), gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(verdadera, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(falsa, gridBagConstraints);
//        combo1.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"-", "A", "E", "I", "O"}));
//        combo1.addActionListener(new ActionListener() {
//            public void actionPerformed(ActionEvent e) {
//                premisa = new Premisa(premisaField.getText());
//                switch (combo1.getSelectedIndex()) {
//                    case 1://A
//                        premisa.convert(ExtensionEnum.A);
//                        break;
//                    case 2://E
//                        premisa.convert(ExtensionEnum.E);
//                        break;
//                    case 3://I
//                        premisa.convert(ExtensionEnum.I);
//                        break;
//                    case 4://O
//                        premisa.convert(ExtensionEnum.O);
//                        break;
//                    case 0://no hace nada
//                        break;
//                }
//                premisaField.setText(premisa.toString());
//            }
//        });
//        gridBagConstraints.gridx = ++x;
//        panel.add(new JLabel(Utiles.createImageIcon(URLEnum.getReference(URLEnum.SPACE_OP))), gridBagConstraints);
//        gridBagConstraints.gridx = ++x;
//        panel.add(combo1, gridBagConstraints);

        premisaField.addCaretListener(new CaretListener() {
            public void caretUpdate(CaretEvent e) {
                if (Premisa.isComplete(premisaField.getText())) {
                    premisa = new Premisa(premisaField.getText());
                    premisaField.setForeground(new Color(0, 0, 0));
                    Premisa auxPremisa = new Premisa(premisaField.getText());
                    auxPremisa.convert(ExtensionEnum.A);
                    firstAnswerTextField.setText(auxPremisa.toString());
                    auxPremisa.convert(ExtensionEnum.E);
                    secondAnswerTextField.setText(auxPremisa.toString());
                    auxPremisa.convert(ExtensionEnum.I);
                    thirdAnswerTextField.setText(auxPremisa.toString());
                    auxPremisa.convert(ExtensionEnum.O);
                    fourthAnswerTextField.setText(auxPremisa.toString());
                } else {
                    premisaField.setForeground(new Color(255, 0, 0));
                }
            }
        });
        return panel;
    }

    private JPanel createCheckLinePanel1() {
        JPanel panel = new JPanel(new GridBagLayout());
        int x = 0;
        int y = 0;
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.add(true1, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(false1, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(indeterminated1, gridBagConstraints);
        return panel;
    }

    private JPanel createCheckLinePanel2() {
        JPanel panel = new JPanel(new GridBagLayout());
        int x = 0;
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.add(true2, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(false2, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(indeterminated2, gridBagConstraints);
        return panel;
    }

    private JPanel createCheckLinePanel3() {
        JPanel panel = new JPanel(new GridBagLayout());
        int x = 0;
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.add(true3, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(false3, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(indeterminated3, gridBagConstraints);
        return panel;
    }

    private JPanel createCheckLinePanel4() {
        JPanel panel = new JPanel(new GridBagLayout());
        int x = 0;
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        panel.add(true4, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(false4, gridBagConstraints);
        gridBagConstraints.gridx = ++x;
        panel.add(indeterminated4, gridBagConstraints);
        return panel;
    }

    private JPanel createScoringPanel() {
        JPanel scoringPanel = new JPanel();
        scoringPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK),
                textBundle.getString(TextBundleEnum.PUNTAJE.toString())));
        scoringPanel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(5, 5, 5, 5);
        scoringPanel.add(addsPoints, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        scoringPanel.add(addsPointsField, gridBagConstraints);
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridx = 0;
        scoringPanel.add(substractPoints, gridBagConstraints);
        gridBagConstraints.gridx = 1;
        scoringPanel.add(substractPointsField, gridBagConstraints);
        return scoringPanel;
    }

    private JPanel createButtonsPanel() {
        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setLayout(new GridBagLayout());
        GridBagConstraints gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(0, 25, 0, 25);
        gridBagConstraints.gridx = 0;
        buttonsPanel.add(previousQuestionButton, gridBagConstraints);//todo PREVIOUS/ADD
        gridBagConstraints.gridx = 1;
        buttonsPanel.add(nextQuestionButton, gridBagConstraints);
        return buttonsPanel;
    }

    private JScrollPane createFullQuestionairePanel() {
        JScrollPane scrollPane = new JScrollPane(fullQuestionaireTextArea);
        scrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.BLACK),
                textBundle.getString(TextBundleEnum.CUESTIONARIO.toString())));
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        return scrollPane;
    }

    private void addButtonsActionListeners() {
        previousQuestionButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setSolution();
                oposicionMCItemSet.previous();
                studentsSolutionsMCItemSet.previous();
                setCurrentQuestionValues();
                premisaField.requestFocus();

            }
        });

        nextQuestionButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (performQuestionCheckings()) {
//                    setSolution();
                    oposicionMCItemSet.next();
                    studentsSolutionsMCItemSet.next();
                    setCurrentQuestionValues();
                    premisaField.requestFocus();
                }
            }
        });

        createExerciseButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (performMCParametersCheckings()) {
                    enableQuestionsPanel(true);
                    enableMCOptionsPanel(false);
                    manageButtonGroup();
                    managePointsFields();
                    clearAllFields();
                }
            }
        });
    }

    private OposicionValuesEnum getStatus(JCheckBox trueCheckBox, JCheckBox falseCheckBox) {
        if (trueCheckBox.isSelected()) {
            return OposicionValuesEnum.TRUE;
        }
        if (falseCheckBox.isSelected()) {
            return OposicionValuesEnum.FALSE;
        }
        return OposicionValuesEnum.INDETERMINATED;
    }

    private void manageButtonGroup() {
        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(true1);
        buttonGroup1.add(false1);
        buttonGroup1.add(indeterminated1);

        ButtonGroup buttonGroup2 = new ButtonGroup();
        buttonGroup2.add(true2);
        buttonGroup2.add(false2);
        buttonGroup2.add(indeterminated2);

        ButtonGroup buttonGroup3 = new ButtonGroup();
        buttonGroup3.add(true3);
        buttonGroup3.add(false3);
        buttonGroup3.add(indeterminated3);

        ButtonGroup buttonGroup4 = new ButtonGroup();
        buttonGroup4.add(true4);
        buttonGroup4.add(false4);
        buttonGroup4.add(indeterminated4);
    }

    private void manageVFLogic() {
        if (premisa != null) {
            checkCheckBoxes(false);
            if (verdadera.isSelected()) {
                vfLogic_v(premisa.getPartsExtension());
            } else {
                vfLogic_f(premisa.getPartsExtension());
            }
        }
    }

    private void vfLogic_v(ExtensionEnum extension) {
        switch (extension) {
            case A:
                true1.setSelected(true);
                false2.setSelected(true);
                true3.setSelected(true);
                false4.setSelected(true);
                break;
            case E:
                false1.setSelected(true);
                true2.setSelected(true);
                false3.setSelected(true);
                true4.setSelected(true);
                break;
            case I:
                indeterminated1.setSelected(true);
                false2.setSelected(true);
                true3.setSelected(true);
                indeterminated4.setSelected(true);
                break;
            case O:
                false1.setSelected(true);
                indeterminated2.setSelected(true);
                indeterminated3.setSelected(true);
                true4.setSelected(true);
                break;
        }
    }

    private void vfLogic_f(ExtensionEnum extension) {
        switch (extension) {
            case A:
                vfLogic_v(ExtensionEnum.O);
                break;
            case E:
                vfLogic_v(ExtensionEnum.I);
                break;
            case I:
                vfLogic_v(ExtensionEnum.E);
                break;
            case O:
                vfLogic_v(ExtensionEnum.A);
                break;
        }

    }

    private void checkCheckBoxes(boolean check) {
        true1.setSelected(check);
        true2.setSelected(check);
        true3.setSelected(check);
        true4.setSelected(check);
        false1.setSelected(check);
        false2.setSelected(check);
        false3.setSelected(check);
        false4.setSelected(check);
        indeterminated1.setSelected(check);
        indeterminated2.setSelected(check);
        indeterminated3.setSelected(check);
        indeterminated4.setSelected(check);
    }

    private void managePointsFields() {
        if (proportionalPunctuationCheckBox.isSelected()) {
            addsPointsField.setEnabled(false);
            substractPointsField.setEnabled(false);
        }
    }

    private void clearAllFields() {
        premisaField.setText("");
        firstAnswerTextField.setText("");
        secondAnswerTextField.setText("");
        thirdAnswerTextField.setText("");
        fourthAnswerTextField.setText("");
        addsPointsField.setText("0");
        substractPointsField.setText("0");
        if (oneAnswerPerQuestionCheckBox.isSelected()) {
            true1.setSelected(true);
        }
    }

    private boolean performQuestionCheckings() {
        if (!Premisa.isComplete(premisaField.getText())) {
            JOptionPane.showMessageDialog(OposicionEvaluationPanel.this,
                    textBundle.getString(TextBundleEnum.WARNING_COMPLETAR_DATOS_MCHOICE.toString()),
                    "", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
    }

    private boolean performMCParametersCheckings() {
        substractProportionalityTextField.setText(substractProportionalityTextField.getText().replace(",", "."));
        if (questionsQuantityTextField.getText().equals("") ||
                substractProportionalityTextField.getText().equals("")) {
            JOptionPane.showMessageDialog(OposicionEvaluationPanel.this,
                    textBundle.getString(TextBundleEnum.WARNING_COMPLETAR_DATOS.toString()),
                    "", JOptionPane.WARNING_MESSAGE);
        } else {
            try {
                if (Integer.parseInt(questionsQuantityTextField.getText()) < 1) {
                    JOptionPane.showMessageDialog(OposicionEvaluationPanel.this,
                            textBundle.getString(TextBundleEnum.WARNING_CANTIDAD_PREGUNTAS_POSITIVO_MAYOR_UNO.toString()) + "!",
                            "", JOptionPane.WARNING_MESSAGE);
                    return false;
                }
            } catch (NumberFormatException e) {
                JOptionPane.showMessageDialog(OposicionEvaluationPanel.this,
                        textBundle.getString(TextBundleEnum.WARNING_CANTIDAD_PREGUNTAS_ENTERO.toString()) + "!",
                        "", JOptionPane.WARNING_MESSAGE);
                return false;
            }
            if (Double.parseDouble(substractProportionalityTextField.getText()) > 1 ||
                    Double.parseDouble(substractProportionalityTextField.getText()) < 0) {
                JOptionPane.showMessageDialog(OposicionEvaluationPanel.this,
                        textBundle.getString(TextBundleEnum.WARNING_PROPORCIONALIDAD_ENTRE_CERO_UNO.toString()) + "!",
                        "", JOptionPane.WARNING_MESSAGE);
                return false;
            }
        }
        return true;
    }

    private void enableQuestionsPanel(boolean enable) {
//        fullQuestionaireTextArea.setEnabled(enable);
//        previousQuestionButton.setEnabled(enable);
//        nextQuestionButton.setEnabled(enable);
//        substractPointsField.setEnabled(enable);
//        addsPointsField.setEnabled(enable);
        premisaField.setEnabled(enable);
        verdadera.setEnabled(enable);
        falsa.setEnabled(enable);
    }

    private void enableAnswers() {
        true1.setEnabled(true);
        true2.setEnabled(true);
        true3.setEnabled(true);
        true4.setEnabled(true);
        false1.setEnabled(true);
        false2.setEnabled(true);
        false3.setEnabled(true);
        false4.setEnabled(true);
        indeterminated1.setEnabled(true);
        indeterminated2.setEnabled(true);
        indeterminated3.setEnabled(true);
        indeterminated4.setEnabled(true);
        firstAnswerTextField.setEditable(true);
        secondAnswerTextField.setEditable(true);
        thirdAnswerTextField.setEditable(true);
        fourthAnswerTextField.setEditable(true);
    }

    private void enableMCOptionsPanel(boolean enable) {
        questionsQuantityTextField.setEnabled(enable);
        substractProportionalityTextField.setEnabled(enable);
        proportionalPunctuationCheckBox.setEnabled(enable);
        oneAnswerPerQuestionCheckBox.setEnabled(enable);
        createExerciseButton.setEnabled(enable);
    }

    public OposicionMCItemSet getMCItemSet() {
        return oposicionMCItemSet;
    }

    public TestExcercise getExercise() throws ExerciseNotBuiltException, PunctuationZeroException {
        if (oposicionMCItemSet.getMCItems().size() < Integer.parseInt(questionsQuantityTextField.getText())
                || addsPointsField.getText().equals("") || substractPointsField.getText().equals("")) {
            throw new ExerciseNotBuiltException();
        }
        if (oposicionMCItemSet.getPuntuation() == 0) {
            throw new PunctuationZeroException();
        }
        return testExercise;
    }

    public void setExercise(TestExcercise testExerciseData) {
        testExercise = testExerciseData;
        this.oposicionMCItemSet = (OposicionMCItemSet) testExercise.getExcerciseData();
        this.studentsSolutionsMCItemSet = (OposicionMCItemSet) testExercise.getStudentsSolution();
        fullQuestionaireTextArea.setText(studentsSolutionsMCItemSet.toString());
        fullQuestionaireTextArea.setCaretPosition(0);
        OposicionMCItem item = oposicionMCItemSet.current();
        premisaField.setText(item.getQuestion());
        verdadera.setSelected(item.isQuestionTrue());
        falsa.setSelected(!item.isQuestionTrue());
        addsPointsField.setText("" + item.getCorrectPunctuation());
        substractPointsField.setText("" + item.getIncorrectPunctuation());
        questionsPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.BLACK),
                textBundle.getString(TextBundleEnum.PREGUNTA.toString()) +
                        " " + (oposicionMCItemSet.getCurrentQuestion()) + " " +
                        textBundle.getString(TextBundleEnum.DE.toString()) + " " +
                        oposicionMCItemSet.getTotalQuestions()));
    }

    private void setCurrentQuestionValues() {
        premisaField.setText(studentsSolutionsMCItemSet.current().getQuestion());
        questionsPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(1,0,0,0,Color.BLACK),
                textBundle.getString(TextBundleEnum.PREGUNTA.toString()) +
                        " " + (oposicionMCItemSet.getCurrentQuestion()) + " " +
                        textBundle.getString(TextBundleEnum.DE.toString()) + " " +
                        oposicionMCItemSet.getTotalQuestions()));
        setStudentSolutionValues();
        premisaField.requestFocus();
    }

    private void setStudentSolutionValues() {
        OposicionValuesEnum[] array = studentsSolutionsMCItemSet.current().getSolutionStatus();
        setCheckBoxValue(true1, false1, indeterminated1, array[0]);
        setCheckBoxValue(true2, false2, indeterminated2, array[1]);
        setCheckBoxValue(true3, false3, indeterminated3, array[2]);
        setCheckBoxValue(true4, false4, indeterminated4, array[3]);
    }

    private void setCheckBoxValue(JCheckBox trueCheck, JCheckBox falseCheck, JCheckBox indeterminatedCheck,
                                  OposicionValuesEnum value) {
        trueCheck.setSelected(false);
        falseCheck.setSelected(false);
        indeterminatedCheck.setSelected(false);
        switch (value) {
            case FALSE:
                falseCheck.setSelected(true);
                break;
            case TRUE:
                trueCheck.setSelected(true);
                break;
            case INDETERMINATED:
                indeterminatedCheck.setSelected(true);
                break;
        }
    }

    private void addCheckBoxesActionListeners() {
        addCheckBoxActionListener(true1, false1, indeterminated1, 1);
        addCheckBoxActionListener(true2, false2, indeterminated2, 2);
        addCheckBoxActionListener(true3, false3, indeterminated3, 3);
        addCheckBoxActionListener(true4, false4, indeterminated4, 4);
    }

    private void addCheckBoxActionListener(JCheckBox trueCheck, JCheckBox falseCheck, JCheckBox indeterminatedCheck,
                                           final int solution) {
        trueCheck.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                studentsSolutionsMCItemSet.current().setSolutionStatus(OposicionValuesEnum.TRUE, solution);
            }
        });
        falseCheck.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                studentsSolutionsMCItemSet.current().setSolutionStatus(OposicionValuesEnum.FALSE, solution);
            }
        });
        indeterminatedCheck.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                studentsSolutionsMCItemSet.current().setSolutionStatus(OposicionValuesEnum.INDETERMINATED, solution);
            }
        });
    }

    private void setButtonsSize(JButton button) {
        button.setPreferredSize(new Dimension(100, 25));
    }

    private void setSolution() {
        studentsSolutionsMCItemSet.current().setQuestion(premisaField.getText());
        studentsSolutionsMCItemSet.current().setSolutions(firstAnswerTextField.getText(), 1);
        studentsSolutionsMCItemSet.current().setSolutionStatus(getStatus(true1, false1), 1);
        studentsSolutionsMCItemSet.current().setSolutions(secondAnswerTextField.getText(), 2);
        studentsSolutionsMCItemSet.current().setSolutionStatus(getStatus(true2, false2), 2);
        studentsSolutionsMCItemSet.current().setSolutions(thirdAnswerTextField.getText(), 3);
        studentsSolutionsMCItemSet.current().setSolutionStatus(getStatus(true3, false3), 3);
        studentsSolutionsMCItemSet.current().setSolutions(fourthAnswerTextField.getText(), 4);
        studentsSolutionsMCItemSet.current().setSolutionStatus(getStatus(true4, false4), 4);

        studentsSolutionsMCItemSet.current().setCorrectPunctuation(Integer.parseInt(addsPointsField.getText()));
        studentsSolutionsMCItemSet.current().setIncorrectPunctuation(Integer.parseInt(substractPointsField.getText()));
        studentsSolutionsMCItemSet.current().setQuestionTrue(verdadera.isSelected());
    }


    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setContentPane(new OposicionEvaluationPanel());
        frame.setSize(new Dimension(500, 500));
        frame.pack();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}
